VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "clsTaskBar"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Type APPBARDATA
    cbSize As Long
    hWnd As Long
    uCallbackMessage As Long
    uEdge As Long
    rc As RECT
    lParam As Long '  message specific
End Type

Private Type NOTIFYICONDATA
    cbSize As Long
    hWnd As Long
    uID As Long
    uFlags As Long
    uCallbackMessage As Long
    hIcon As Long
    szTip As String * 64
End Type

Private Declare Function Shell_NotifyIcon& Lib "shell32.dll" _
Alias "Shell_NotifyIconA" (ByVal dwMessage&, _
lpData As NOTIFYICONDATA)

Private Declare Function SHAppBarMessage& Lib "shell32.dll" _
(ByVal dwMessage&, pData As APPBARDATA)

Private Const NIM_ADD = 0&
Private Const NIM_DELETE = 2&
Private Const NIM_MODIFY = 1&
Private Const NIF_ICON = 2&
Private Const NIF_MESSAGE = 1&
Private Const NIF_TIP = 4&

Const ABM_GETTASKBARPOS = &H5
Private udtNotify As NOTIFYICONDATA
Private udtAppBarData As APPBARDATA

Private Const WM_USER = &H400
Private Const MYWM_NOTIFYICON = WM_USER + &H301


Public Property Let hWnd(F As Form)
    
'Assigns the app's hwnd to the notification structure
udtNotify.hWnd = F.hWnd

End Property


Public Property Get CallbackMessage%()

'Returns the message number that Windows will use to notify
'the app of mouse events
CallbackMessage = udtNotify.uCallbackMessage

End Property


Public Sub AddIconToTray(hIcon&, ID&)

'Adds a new icon to the system tray

Dim lResult&

udtNotify.uID = ID
udtNotify.hIcon = hIcon
udtNotify.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
lResult = Shell_NotifyIcon(NIM_ADD, udtNotify)

End Sub

Public Function TaskbarExists&()

'Verify that the task bar exists.  If the user is using a
'3rd party shell, it might not.
udtAppBarData.cbSize = 36&
TaskbarExists = SHAppBarMessage(ABM_GETTASKBARPOS, udtAppBarData)

End Function


Public Sub ChangeTip(sNewTip$, ID&)
    
'Changes the text displayed when the user pauses
'the mouse over the icon.

Dim lResult&

udtNotify.szTip = sNewTip & Chr$(0)
udtNotify.uID = ID
udtNotify.uFlags = NIF_TIP
lResult = Shell_NotifyIcon(NIM_MODIFY, udtNotify)

End Sub

Public Sub DeleteIcon(ID&)
    
'Deletes the specified icon from the system tray
Dim lResult&

udtNotify.uID = ID
lResult = Shell_NotifyIcon(NIM_DELETE, udtNotify)

End Sub

Public Sub DeleteAllIcons(nIcons%)

Dim iCounter%
Dim lResult&

For iCounter = 1 To nIcons
    udtNotify.uID = iCounter
    lResult = Shell_NotifyIcon(NIM_DELETE, udtNotify)
Next iCounter

End Sub

Private Sub Class_Initialize()

'Initialize elements of the data structure
udtNotify.cbSize = 88&
udtNotify.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
udtNotify.uCallbackMessage = MYWM_NOTIFYICON
udtNotify.szTip = ""

End Sub

